//
//  MeetingView.m
//  Gxj
//
//  Created by 💋索少杰 on 2017/9/8.
//  Copyright © 2017年 wkq. All rights reserved.
//

#import "MeetingView.h"

@interface MeetingView ()<UIPickerViewDelegate,UIPickerViewDataSource,UITextViewDelegate>
{
    NSArray *_province;
    NSDictionary *_city;
}
@property(nonatomic, strong)UIPickerView *picker;

#define Start_X          180.0f      // 第一个按钮的X坐标
#define Start_Y          75.0f     // 第一个按钮的Y坐标
#define Width_Space      15.0f      // 2个按钮之间的横间距
#define Height_Space     20.0f     // 竖间距
#define Button_Height   15.0f    // 高
#define Button_Width    30.0f    // 宽


@end

@implementation MeetingView

- (instancetype) initWithFrame:(CGRect)frame{
    if (self == [super initWithFrame:frame]) {
        
        [self addSubview:self.view1];
        [self addSubview:self.textContent];
        [self addSubview:self.link1];
        [self addSubview:self.labelText];
        [self addSubview:self.downchoiceHY];
        [self addSubview:self.link2];
        [self addSubview:self.bianjiMeeting];
        [self addSubview:self.link3];
        [self addSubview:self.viewAdd];
        [self addSubview:self.link4];
        [self addSubview:self.timeText];
        [self addSubview:self.view2];
        [self addSubview:self.view3];
        [self addSubview:self.imageTime];
        [self addSubview:self.fabuMeeting];
        

        _textContent.sd_layout
        .topSpaceToView(self, kHeightScale(10))
        .leftSpaceToView(self, kWidthScale(5))
        .rightSpaceToView(self, kWidthScale(10))
        .heightIs(40);
        
        _link1.sd_layout
        .topSpaceToView(self.textContent, kHeightScale(10))
        .leftSpaceToView(self, kWidthScale(0))
        .rightSpaceToView(self, kWidthScale(0))
        .heightIs(kHeightScale(1));
        
        _labelText.sd_layout
        .topSpaceToView(self.link1, kHeightScale(15))
        .leftSpaceToView(self, kWidthScale(10))
        .widthIs(kWidthScale(140))
        .autoHeightRatio(0);

        //商业标签
        NSArray*arr=@[@"shangye",@"fuzhuang",@"UI"];
        for (int i = 0 ; i < 3; i++) {
            NSInteger index = i % 3;
            NSInteger page = i / 3;
            
            // 圆角按钮
            UIButton *mapBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
            mapBtn.tag = i;//这句话不写等于废了
            mapBtn.frame = CGRectMake(index * (Button_Width + Width_Space) + Start_X, page  * (Button_Height + Height_Space)+Start_Y, Button_Width, Button_Height);
            [mapBtn setBackgroundImage:[UIImage imageNamed:arr[index]] forState:UIControlStateNormal];
            [self addSubview:mapBtn];
            //按钮点击方法
            [mapBtn addTarget:self action:@selector(mapBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        }
        
        _downchoiceHY.sd_layout
        .topSpaceToView(self.link1, kHeightScale(15))
        .rightSpaceToView(self, kWidthScale(15))
        .widthIs(kWidthScale(10))
        .heightIs(kHeightScale(10));
        
        _link2.sd_layout
        .topSpaceToView(self.labelText, kHeightScale(15))
        .leftSpaceToView(self, kWidthScale(0))
        .rightSpaceToView(self, kWidthScale(0))
        .heightIs(kHeightScale(1));
        
        _bianjiMeeting.sd_layout
        .topSpaceToView(self.link2, kHeightScale(5))
        .leftSpaceToView(self, kWidthScale(5))
        .rightSpaceToView(self, kWidthScale(10))
        .heightIs(100);
        
        _link3.sd_layout
        .topSpaceToView(self.bianjiMeeting, kHeightScale(0))
        .leftSpaceToView(self, kWidthScale(0))
        .rightSpaceToView(self, kWidthScale(0))
        .heightIs(kHeightScale(1));
        
        _viewAdd.sd_layout
        .topSpaceToView(self.link3, kHeightScale(10))
        .leftSpaceToView(self, kWidthScale(10))
        .rightSpaceToView(self, kWidthScale(10))
        .heightIs(kHeightScale(100));
        
        _link4.sd_layout
        .topSpaceToView(self.viewAdd, kHeightScale(15))
        .leftSpaceToView(self, kWidthScale(0))
        .rightSpaceToView(self, kWidthScale(0))
        .heightIs(kHeightScale(1));
        
        _timeText.sd_layout
        .topSpaceToView(self.link4, kHeightScale(20))
        .leftSpaceToView(self, kWidthScale(10))
        .widthIs(kWidthScale(160))
        .autoHeightRatio(0);
        
        _view2.sd_layout
        .topSpaceToView(self.timeText, kHeightScale(24))
        .leftSpaceToView(self, kWidthScale(100))
        .widthIs(kWidthScale(62))
        .heightIs(kHeightScale(36));
        
        _view3.sd_layout
        .topSpaceToView(self.timeText, kHeightScale(24))
        .leftSpaceToView(self.view2, kWidthScale(40))
        .widthIs(kWidthScale(62))
        .heightIs(kHeightScale(36));
        
        _imageTime.sd_layout
        .topSpaceToView(self.timeText, kHeightScale(34))
        .leftSpaceToView(self.view2, kWidthScale(17))
        .rightSpaceToView(self.view3, kWidthScale(17))
        .heightIs(15);
        
        _fabuMeeting.sd_layout
        .topSpaceToView(self.view1, kHeightScale(60))
        .leftSpaceToView(self, kWidthScale(20))
        .rightSpaceToView(self, kWidthScale(20))
        .heightIs(kHeightScale(40));
                        
        
        [self setPickerView];
    }
    
    return self;
}

- (void)mapBtnClick:(UIButton *)sender
{
    
}

//设置阴影
- (UIView *)view1
{
    if (!_view1)
    {
        _view1 = [[UIView alloc] init];
        _view1=[[UIView alloc] initWithFrame:CGRectMake(0, kWidthScale(0), UIScreenWidth, kHeightScale(460))];
        _view1.backgroundColor =[UIColor whiteColor];
        _view1.backgroundColor = [UIColor colorWithWhite:0 alpha:0.3];
    }
    return _view1;
}
- (UITextView *)textContent
{
    if (!_textContent)
    {
        _textContent = [[UITextView alloc] init];
        _textContent.text=@"请输入会议标题(必填)";
        [_textContent setValue:[UIColor whiteColor] forKeyPath:@"_placeholderLabel.textColor"];
        _textContent.textColor=[UIColor whiteColor];
        _textContent.backgroundColor = [UIColor colorWithWhite:0 alpha:0.0];
        _textContent.delegate=self;
        _textContent.font=[UIFont systemFontOfSize:kWidthScale(16)];
    }
    return _textContent;
}
//虚线
- (UIImageView *)link1
{
    if (!_link1)
    {
        _link1 = [[UIImageView alloc] init];
        _link1.image = [UIImage imageNamed:@"hui"];
    }
    return _link1;
}
//会议标题
- (UILabel *)labelText
{
    if (!_labelText)
    {
        _labelText = [[UILabel alloc] init];
        _labelText.text=@"请选择相应标签(必填)";
        _labelText.textColor=[UIColor whiteColor];
        _labelText.font=[UIFont systemFontOfSize:kWidthScale(12)];
    }
    return _labelText;
}
//点击下拉按钮
- (UIButton *)downchoiceHY
{
    if (!_downchoiceHY)
    {
        _downchoiceHY=[[UIButton alloc] init];
        //        _downchoiceHY.backgroundColor=[UIColor lightGrayColor];
        [_downchoiceHY setBackgroundImage:[UIImage imageNamed:@"xiala"] forState:UIControlStateNormal];
    }
    return _downchoiceHY;
}
- (UIImageView *)link2
{
    if (!_link2)
    {
        _link2 = [[UIImageView alloc] init];
        _link2.image = [UIImage imageNamed:@"hui"];
    }
    return _link2;
}
- (UITextView *)bianjiMeeting
{
    if (!_bianjiMeeting)
    {
        _bianjiMeeting = [[UITextView alloc] init];
        _bianjiMeeting.text=@"请编辑会议简介：";
        [_bianjiMeeting setValue:[UIColor whiteColor] forKeyPath:@"_placeholderLabel.textColor"];
        _bianjiMeeting.backgroundColor = [UIColor colorWithWhite:0 alpha:0.0];
        _bianjiMeeting.textColor=[UIColor whiteColor];
        _bianjiMeeting.delegate=self;
        _bianjiMeeting.font=[UIFont systemFontOfSize:kWidthScale(15)];
    }
    return _bianjiMeeting;
}
- (UIImageView *)link3
{
    if (!_link3)
    {
        _link3 = [[UIImageView alloc] init];
        _link3.image = [UIImage imageNamed:@"hui"];
    }
    return _link3;
}
//添加封面
- (UIView *)viewAdd
{
    if (!_viewAdd)
    {
        _viewAdd = [[UIView alloc] init];
        _viewAdd.backgroundColor =[UIColor whiteColor];
        _viewAdd.layer.masksToBounds=YES;
        _viewAdd.layer.cornerRadius=kWidthScale(10);
        _viewAdd.backgroundColor = [UIColor colorWithWhite:0 alpha:0.4];
    }
    return _viewAdd;
}
- (UIImageView *)link4
{
    if (!_link4)
    {
        _link4 = [[UIImageView alloc] init];
        _link4.image = [UIImage imageNamed:@"hui"];
    }
    return _link4;
}

- (UILabel *)timeText
{
    if (!_timeText)
    {
        _timeText = [[UILabel alloc] init];
        _timeText.text=@"请选择会议发布时间";
        _timeText.textColor=[UIColor whiteColor];
        _timeText.font=[UIFont systemFontOfSize:kWidthScale(12)];
    }
    return _timeText;
}

- (UIImageView *)imageTime
{
    if (!_imageTime)
    {
        _imageTime = [[UIImageView alloc] init];
        _imageTime.image=[UIImage imageNamed:@"shijian"];
    }
    return _imageTime;
}

- (UIView *)view2
{
    if (!_view2)
    {
        _view2 = [[UIView alloc] init];
        _view2.backgroundColor =[UIColor whiteColor];
        _view2.backgroundColor = [UIColor colorWithWhite:0 alpha:0.3];
        _view2.layer.masksToBounds=YES;
        _view2.layer.cornerRadius=10;
    }
    return _view2;
}

- (UIView *)view3
{
    if (!_view3)
    {
        _view3 = [[UIView alloc] init];
        _view3.backgroundColor =[UIColor whiteColor];
        _view3.backgroundColor = [UIColor colorWithWhite:0 alpha:0.3];
        _view3.layer.masksToBounds=YES;
        _view3.layer.cornerRadius=10;
    }
    return _view3;
}
- (UIButton *)fabuMeeting
{
    if (!_fabuMeeting)
    {
        _fabuMeeting = [UIButton buttonWithType:UIButtonTypeCustom];
        [_fabuMeeting setBackgroundImage:[UIImage imageNamed:@"fabuhuiyibg123"] forState:UIControlStateNormal];
        
    }
    return _fabuMeeting;
}
# pragma mark - 时间PickView
- (void)setPickerView{
    
    //小时
    _province=@[@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10",@"11",@"12"];
    
    //分钟
    _city = @{
              @"1":@[@"00",@"01", @"02", @"03",@"04",@"05",@"06",@"07",@"08",@"09",@"10",@"11",@"12",@"13",@"14",@"15",@"16",@"17",@"18",@"19",@"20",@"21",@"22",@"23",@"24",@"25",@"26",@"27",@"28",@"29",@"30",@"31",@"32",@"33",@"34",@"35",@"36",@"37",@"38",@"39",@"40",@"41",@"42",@"43",@"44",@"45",@"46",@"47",@"48",@"49",@"50",@"51",@"52",@"53",@"54",@"55",@"56",@"57",@"58",@"59"]
              };
    _picker=[[UIPickerView alloc] init];
    //_picker.backgroundColor=[UIColor orangeColor];
    _picker.delegate = self;
    _picker.dataSource = self;
    [self addSubview:_picker];
    
    _picker.sd_layout
    .topSpaceToView(self.link4, kHeightScale(56))
    .leftSpaceToView(self, kWidthScale(88))
    .rightSpaceToView(self, kWidthScale(50))
    .heightIs(kHeightScale(40));
    
    
    
    
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 2;
}
- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component
{
    if (component == 0)
    {
        return 40;
    }
    else
    {
        return 160;
    }
    
    return 0;
}
- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component
{
    return 60;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    switch (component) {
        case 0:
        {
            return _province.count;
        }
            break;
        case 1:
        {
            NSInteger integer=[pickerView selectedRowInComponent:0];
            NSString *province =_province[integer];
            NSArray *citys = [_city objectForKey:province];
            
            return citys.count;
        }
            break;
            
            break;
        default:
            break;
    }
    
    return 0;
}
- (nullable NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    switch (component) {
        case 0:
        {
            return _province[row];
        }
            break;
        case 1:
        {
            NSInteger integer=[pickerView selectedRowInComponent:0];
            NSString *province = _province[integer];
            NSArray *citys = [_city objectForKey:province];
            return citys[row];
            
        }
            break;
            
        default:
            break;
    }
    
    return nil;
}
#pragma mark - UITextViewDelegate 文本输入
- (void)textViewDidEndEditing:(UITextView *)textContent
{
    if(textContent.text.length < 1){
        textContent.text = @"请输入会议标题(必填)：";
        textContent.textColor = [UIColor whiteColor];
    }else if (_bianjiMeeting.text.length < 1){
        textContent.text = @"请编辑会议简介：";
        textContent.textColor = [UIColor whiteColor];
    }
}
- (void)textViewDidBeginEditing:(UITextView *)textContent
{
    if([textContent.text isEqualToString:@"请输入会议标题(必填)："]){
        textContent.text=@"";
        textContent.textColor=[UIColor whiteColor];
    }else if ([_bianjiMeeting.text isEqualToString:@"请编辑会议简介："]){
        textContent.text=@"";
        textContent.textColor=[UIColor whiteColor];
    }
}







@end
